import pymysql

db = pymysql.connect(
    host='localhost',
    user='root',
    password='1231',
    database='scrapy_demo'
)
#
#
# def insert(name, age, mdb=db):
#     cursor = mdb.cursor()
#     try:
#         print("insert into test_tb(name,age) values('" + name + "'," + str(age) + ")")
#         cursor.execute("insert into test_tb(name,age) values('" + name + "'," + str(age) + ")")
#     finally:
#         mdb.commit()
#
# def test_func():
#     test_str = ' ￥14999'
#     print(int(test_str.replace('￥','').replace(' ', '')))
# # insert('wu-xz',38,db)
# test_func()

import re


def convert_to_gb(value_with_unit):
    # 匹配数字和单位（GB 或 TB）
    match = re.match(r'(\d+)(GB|TB)', value_with_unit, re.IGNORECASE)
    if match:
        value = int(match.group(1))  # 获取数字部分
        unit = match.group(2).upper()  # 获取单位部分，统一转为大写
        if unit == 'TB':
            return value * 1024  # TB 转 GB
        elif unit == 'GB':
            return value
    return 0  # 如果不匹配，返回 0


original_string = "128GB+8GB>".strip()
if '+' in original_string:
    parts = original_string.split('+')  # 分割加号部分
    total_gb = sum(convert_to_gb(part) for part in parts)
else:
    total_gb = convert_to_gb(original_string)

print(total_gb)